package com.yuexunit.finance.system.service;

import java.util.List;

import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Restrictions;

import com.yuexunit.finance.system.entity.FinanceFilesNormEntity;
import com.yuexunit.inject.annotation.Implements;
import com.yuexunit.page.PageCriteria;
import com.yuexunit.page.PageList;
import com.yuexunit.persist.PersistUtil;
import com.yuexunit.persist.annotation.Transactional;
import com.yuexunit.util.DateUtil;

/**
*@version 创建时间：2017年3月10日 下午4:08:14
*@author wenwenlong
*类说明
*/

@Implements(FinanceFilesNormService.class)
public class FinanceFilesNormServiceImpl implements FinanceFilesNormService {

	@Override
	@Transactional
	public Long createFinanceFilesNorm(FinanceFilesNormEntity entity) {
		entity.setCreateDateTime(DateUtil.now());
		entity.setUpdateDateTime(DateUtil.now());
		PersistUtil.insert(entity);
		return entity.getNormId();
	}

	@Override
	@Transactional
	public void updateFinanceFilesNorm(FinanceFilesNormEntity entity) {
		entity.setUpdateDateTime(DateUtil.now());
		PersistUtil.update(entity);
	}
	
	@Override
	@Transactional
	public void deleteFinanceFilesNorm(Long normId) {
		PersistUtil.delete(FinanceFilesNormEntity.class, normId);
	}

	@Override
	public FinanceFilesNormEntity inquireFinanceFilesNormDetail(Long normId) {
		return PersistUtil.get(FinanceFilesNormEntity.class, normId);
	}

	@Override
	public PageList<FinanceFilesNormEntity> inquireFinanceFilesNormPageList(Integer filesType, PageCriteria page) {
		DetachedCriteria criteria = DetachedCriteria.forClass(FinanceFilesNormEntity.class);
		if(filesType != null) {
			criteria.add(Restrictions.eq("filesType", filesType));
		}
		return PersistUtil.get(criteria, page);
	}

	@Override
	public List<FinanceFilesNormEntity> inquireFinanceFilesNormList() {
		DetachedCriteria criteria = DetachedCriteria.forClass(FinanceFilesNormEntity.class);
		return PersistUtil.get(criteria);
	}
}
